package cn.jee.jsp;

import cn.jee.jsp.util.JdbcUtil;
import cn.jee.jsp.util.StuRowProcessor;
import jakarta.servlet.ServletException;
import jakarta.servlet.annotation.WebServlet;
import jakarta.servlet.http.HttpServlet;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import jakarta.servlet.http.HttpSession;
import cn.jee.jsp.domain.Stu;
import java.io.IOException;
import java.util.List;
@WebServlet("/editStu")
public class EditStuServlet extends HttpServlet {

  @Override
  protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    doPost(req, resp);
  }

  @Override
  protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String id=req.getParameter("id");
    String sql="select * from stu where id=?";
    Object[] args={id};
    Stu res=JdbcUtil.queryByObj(sql,args,new StuRowProcessor()).get(0);
    HttpSession session = req.getSession();
    session.setAttribute("stu", res);
    resp.sendRedirect(req.getContextPath() + "/stu/stu_edit.jsp");
  }
}
